//
//  BNDHomeOfficeDocTipView.m
//  OfficeDoc
//
//  Created by pie on 2022/3/31.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDHomeOfficeDocTipView.h"
#import "UIImageView+LKWebImage.h"

@interface BNDHomeOfficeDocTipView ()
@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UILabel * titleLabel;
@property (strong, nonatomic) UILabel * subtitleLabel;
@property (strong, nonatomic) UIView * dotView;
@property (strong, nonatomic) UIImageView * iconImageView;
@end

@implementation BNDHomeOfficeDocTipView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColorWithHex(0xf5f5f5);
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = UIColor.whiteColor;
        _bgView.layer.cornerRadius = 16;
        _bgView.layer.masksToBounds = YES;
        [self addSubview:_bgView];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(12, 12, 0, 12));
        }];
        
        _iconImageView = [[UIImageView alloc] initWithImage:BNDImageNamed(@"bnd_home_tuis_news")];
        [_bgView addSubview:_iconImageView];
        [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.bgView.mas_left).offset(16);
            make.centerY.mas_equalTo(self.bgView);
            make.size.mas_equalTo(CGSizeMake(74, 50));
        }];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = BNDPFHeavyFont(15);
        _titleLabel.textColor = UIColor.blackColor;
        _titleLabel.text = @"最新的1条公告内跟置顶无关最新的1条公告内跟置顶无关";
        _titleLabel.numberOfLines = 1;
        [_bgView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
            make.right.mas_equalTo(self.bgView.mas_right).offset(-50);
            make.top.mas_equalTo(self.iconImageView);
        }];
        
        _subtitleLabel = [[UILabel alloc] init];
        _subtitleLabel.font = BNDPFHeavyFont(15);
        _subtitleLabel.textColor = UIColor.blackColor;
        _subtitleLabel.text = @"春节放假通知";
        _subtitleLabel.numberOfLines = 1;
        [_bgView addSubview:_subtitleLabel];
        [_subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
            make.right.mas_equalTo(self.bgView.mas_right).offset(-50);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(6);
        }];
        
        UIImageView *moreImageView = [[UIImageView alloc] initWithImage:BNDImageNamed(@"bnd_icons_more")];
        [_bgView addSubview:moreImageView];
        [moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.bgView.mas_right).offset(-12);
            make.centerY.mas_equalTo(self.bgView);
            make.size.mas_equalTo(CGSizeMake(14, 32));
        }];
        
        _dotView = [[UIView alloc] init];
        _dotView.backgroundColor = UIColorWithHex(0xF85757);
        _dotView.layer.cornerRadius = 4;
        _dotView.layer.masksToBounds = YES;
        [self addSubview:_dotView];
        [self.dotView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(8, 8));
            make.right.mas_equalTo(moreImageView.mas_left).offset(-3);
            make.centerY.mas_equalTo(moreImageView);
        }];
        
        @weakify(self)
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(id x) {
           @strongify(self)
            BND_BLOCK_EXEC(self.block,self.model);
        }];
        [self addGestureRecognizer:tap];
    }
    
    return self;
}

- (void)setModel:(BNDOfficeDocModel *)model
{
    _model = model;
    
    _titleLabel.text =  model.title;
    _subtitleLabel.text = model.classificationName;
    [_iconImageView lk_setImageFadeWithURLStr:[[BNDPreference sharedInstance] handleProduceImageUrl:model.coverPic] placeholder:BNDImageNamed(@"bnd_home_tuis_news")];
    self.dotView.hidden = model.unread;
}

@end
